#include <stdint.h>
#include <vector>

#ifndef BASE
#define BASE
#include "base.cpp"
#endif

#ifndef CONSTANT
#define CONSTANT
#include "constant.cpp"
#endif

using namespace std;


const string* attr_code_str , *attr_constantVal_str,
*attr_deprecated_str , *attr_exceptions_str,
*attr_innerClasses_str , *attr_lineNumberTable_str,
*attr_localVariableTable_str , *attr_sourceFile_str,
*attr_synthetic_str ;

enum attr_type {t_exception, t_code, t_lineNumberTable, t_constantValueAttr, t_innerClass, t_deprecated, t_synthetic};


class AttributeInfo {
    public:
    uint16_t attr_name_idx;
    uint32_t attr_len;
    int type;
};


class ExceptionAttr : public AttributeInfo{
    public:
    uint16_t exception_num;
    uint16_t exception_idx;
    ExceptionAttr() {
        type = t_exception;
    }
};


class ExceptionInfo {
    public:
    uint16_t start_pc;
    uint16_t end_pc;
    uint16_t handler_pc;
    uint16_t catch_type;
};

//Code属性，用于存储字节码指令
class CodeAttr : public AttributeInfo {
    public:
    uint16_t max_stack;
    uint16_t max_locals;
    uint32_t code_len;
    const uint8_t* codes;
    uint16_t exception_tbl_len;
    vector<ExceptionInfo*> *exception_tbl = new vector<ExceptionInfo*>();
    uint16_t attr_count;
    vector<AttributeInfo*> *attrs = new vector<AttributeInfo*>();

    CodeAttr() {
        type = t_code;
    }
};


class LineNumberInfo {
    public:
    uint16_t start_pc;
    uint16_t line_number;
};

//描述java源码行号与字节码行号关系
class LineNumberTable : public AttributeInfo {
    public:
    uint16_t attr_name_idx;
    uint32_t attr_len;
    uint16_t line_num_tbl_len;
    vector<LineNumberInfo*> *infos = new vector<LineNumberInfo*>();
    LineNumberTable() {
        type = t_lineNumberTable;
    }
};

//非默认生成
// class LocalVariableTable : public AttributeInfo {
//     uint16_t attr_name_idx;
//     uint32_t attr_len;
//     uint16_t local
// };

//通知虚拟机为静态变量赋值
class ConstantValueAttr : public AttributeInfo {
    public:
    uint16_t constantVal_idx;
    ConstantValueAttr() {
        type = t_constantValueAttr;
    }
};


class InnerClassesInfo {
    public:
    uint16_t inner_class_idx;
    uint16_t outer_class_idx;
    uint16_t inner_name_idx;
    uint16_t inner_class_access_flags;
};



class InnerClassesAttr : public AttributeInfo {
    public:
    uint16_t classes_num;
    vector<InnerClassesInfo*> *infos = new vector<InnerClassesInfo*>();
    InnerClassesAttr(){
        type = t_innerClass;
    }
};

class DeprecatedAttr : public AttributeInfo {
    public:
    DeprecatedAttr(){
        type = t_deprecated;
    }
};

class SyntheticAttr : public AttributeInfo {
    public:
    SyntheticAttr(){
        type = t_synthetic;
    }
};